package com.account.web.controller.system;

import com.account.common.core.controller.BaseController;
import com.account.common.core.domain.R;
import com.account.common.core.domain.entity.SysUser;
import com.account.common.enums.ChannelUserType;
import com.account.common.utils.SecurityUtils;
import com.account.common.utils.StringUtils;
import com.account.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 渠道Controller
 *
 * @author a
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/system/channel")
public class ChannelUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询渠道用户列表
     */
    @GetMapping("/list")
    public R<List<SysUser>> list() {
        String userType = SecurityUtils.getUserType();
        SysUser sysUser = new SysUser();
        sysUser.setAncestors(SecurityUtils.getUserId().toString());
        List<SysUser> list = sysUserService.selectUserList(sysUser);

        if (!ChannelUserType.SUPER_ADMIN.getCode().equals(userType)) {
            SysUser user = sysUserService.selectUserById(SecurityUtils.getUserId());
            list.add(user);
        }
        list.forEach(user -> {
            user.setPassword(StringUtils.EMPTY);
        });
        return R.ok(list);
    }
}
